<?php
/**
 * ============================================================================
 * 版权所有 2008-2011 多多网络，并保留所有权利。
 * 网站地址: http://soft.duoduo123.com；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
*/
session_start();
include_once 'comm/config.php';
include_once 'comm/Taoapi.php';
include_once 'comm/page.class.php';
include_once 'comm/checkpostandget.php';
$no_words = include ('cache/no_words.php');
$tao_id_arr = include ('data/tao_ids.php');

$Taoapi_Config = Taoapi_Config::Init();
$Taoapi_Config->setCharset('UTF-8');

$Taoapi = new Taoapi;

function get_fan($title,$nick,$p){
	$Taoapi = new Taoapi;
    $Taoapi->method = 'taobao.taobaoke.items.get';
    $Taoapi->fields = 'title,nick,price,click_url,shop_click_url,commission';
    $Taoapi->nick = MYUSERNICK;
    $Taoapi->keyword=$title;
    $Taoapi->page_size=20;
	$Taoapi->sort='commissionNum_desc';
    $Taoapi->outer_code = $_SESSION['dduserid'];
    $TaobaokeData = $Taoapi->Send('get','xml')->getArrayData();
	$arr=$TaobaokeData['taobaoke_items']['taobaoke_item'];
	if($arr[0]=='') $row[0]=$arr;
	else $row=$arr;
	for($i=0;$i<count($row);$i++){
	    if($row[$i]['nick']==$nick && strip_tags($row[$i]['title'])==$title){
		    $re=$row[$i];
			$i=9999999;
		}
	}
	if($p=='commission') return $re['commission'];
	if($p=='click_url') return $re['click_url'];
}

//iid加密
$iid=decode_url($_GET['iid']);
$iid=(float)$iid;
$url=$_GET['url'];
$search=(int)$_GET['search'];
$tmall=0;
if(isset($_GET['q']) && reg_taobao_url($_GET['q'])==1){
	$q=$_GET['q'];
	$iid=(float)get_tao_id($q,$tao_id_arr);
	if(preg_match('/(tmall\.com)/',$q)==1){
		$tmall=1;
	}
	
}
elseif($search==1){
	$q=$_GET['q'];
	if(SEARCHS8==1){
		if($q=='' || urlencode($q)=='+'){
		    $url='http://s8.taobao.com/list.html?&pid=mm_'.MYUSERPID.'_0_0&commend=all&unid='.$_SESSION['dduserid'].'&taoke_type=1';
		}else{
		    $Taoapi->method = 'taobao.taobaoke.listurl.get';
	        $Taoapi->q = $q;
	        $Taoapi->nick = MYUSERNICK;
            $Taoapi->outer_code=$_SESSION['dduserid'];
	        $TaobaokeData = $Taoapi->Send('get','xml')->getArrayData();
	        $url=$TaobaokeData['taobaoke_item']['keyword_click_url'].'&taoke_type=1';
		}
	    echo "<script>window.location='gotos8.php?url=".rawurlencode(base64_encode($url))."'</script>";
	    exit;
	}
	else{
		echo "<script>alert('直接搜索淘宝商品网址即可查询返利');function CloseWin(){ window.opener=null; window.open('','_self'); window.close(); } CloseWin();</script>";
		exit;
	}
}

$goods_exists=0;

$Taoapi->method = 'taobao.taobaoke.items.detail.get';
$Taoapi->nick = MYUSERNICK;
$Taoapi->num_iids = $iid;
$Taoapi->outer_code=$_SESSION["dduserid"];

if(WEBTYPE==1){
    $Taoapi->fields = 'iid,detail_url,num_iid,title,nick,type,cid,desc,pic_url,num,list_time,delist_time,stuff_status,location,price,post_fee,express_fee,ems_fee,has_discount,freight_payer,seller_credit_score,shop_click_url,click_url,volume,stuff_status,has_invoice,cid,auction_point';
}
else{
    $Taoapi->fields = 'iid,detail_url,num_iid,title,nick,type,cid,pic_url,num,list_time,delist_time,stuff_status,location,price,post_fee,express_fee,ems_fee,has_discount,freight_payer,seller_credit_score,shop_click_url,click_url,volume,stuff_status,has_invoice,cid,auction_point';
}
$TaobaokeData = $Taoapi->Send('get','xml')->getArrayData();

$titles = $TaobaokeData["taobaoke_item_details"]["taobaoke_item_detail"]["item"]["title"];

if ($titles != '') {
    $type = $TaobaokeData["taobaoke_item_details"]["taobaoke_item_detail"]["item"]["type"]; 
    $cid = $TaobaokeData["taobaoke_item_details"]["taobaoke_item_detail"]["item"]["cid"]; 
    $sellernick = $TaobaokeData["taobaoke_item_details"]["taobaoke_item_detail"]["item"]["nick"]; 
    $usernick=$sellernick;
    $post_fee = $TaobaokeData["taobaoke_item_details"]["taobaoke_item_detail"]["item"]["post_fee"]; 
    $express_fee = $TaobaokeData["taobaoke_item_details"]["taobaoke_item_detail"]["item"]["express_fee"]; 
    $ems_fee = $TaobaokeData["taobaoke_item_details"]["taobaoke_item_detail"]["item"]["ems_fee"]; 
    $desc = $TaobaokeData["taobaoke_item_details"]["taobaoke_item_detail"]["item"]["desc"]; 
    $num = $TaobaokeData["taobaoke_item_details"]["taobaoke_item_detail"]["item"]["num"]; 
    $price = $TaobaokeData["taobaoke_item_details"]["taobaoke_item_detail"]["item"]["price"]; 
    $pic_path = $TaobaokeData["taobaoke_item_details"]["taobaoke_item_detail"]["item"]["pic_url"]; 
    $list_time = $TaobaokeData["taobaoke_item_details"]["taobaoke_item_detail"]["item"]["list_time"]; 
    $delist_time = $TaobaokeData["taobaoke_item_details"]["taobaoke_item_detail"]["item"]["delist_time"]; 
    $freight_payer = $TaobaokeData["taobaoke_item_details"]["taobaoke_item_detail"]["item"]["freight_payer"]; 
    $stuff_status= $TaobaokeData["taobaoke_item_details"]["taobaoke_item_detail"]["item"]["stuff_status"]; 
    $has_invoice= $TaobaokeData["taobaoke_item_details"]["taobaoke_item_detail"]["item"]["has_invoice"]; 
    $volume=$TaobaokeData["taobaoke_item_details"]["taobaoke_item_detail"]["volume"]; 
    $state=$TaobaokeData["taobaoke_item_details"]["taobaoke_item_detail"]["item"]["location"]["state"]; 
    $city=$TaobaokeData["taobaoke_item_details"]["taobaoke_item_detail"]["item"]["location"]["city"]; 
    $cid=$TaobaokeData["taobaoke_item_details"]["taobaoke_item_detail"]["item"]["cid"]; 
    $shop_click_url=$TaobaokeData["taobaoke_item_details"]["taobaoke_item_detail"]["shop_click_url"]; 
    $click_url=$TaobaokeData["taobaoke_item_details"]["taobaoke_item_detail"]["click_url"]; 

    if($freight_payer=="seller"){$freight_payer="卖家承担";}else{$freight_payer="买家承担";}
    $desc=preg_replace("/(?<=href=)([^\>]*)(?=\>)/i","#", $desc);

    //获取该商品的返现金额
    $Taoapi->method = 'taobao.taobaoke.items.convert';
    $Taoapi->fields = 'commission';
    $Taoapi->nick =  MYUSERNICK;
    $Taoapi->num_iids=$iid;
    $CommData = $Taoapi->Send('get','xml')->getArrayData();
    if($CommData['taobaoke_items']['taobaoke_item']['commission']==''){
        $CommData['taobaoke_items']['taobaoke_item']['commission']=get_fan($titles,$sellernick,'commission');
    }
    $ThisComm=ck_fxje($CommData['taobaoke_items']['taobaoke_item']['commission'],$_SESSION["dduserlevel"]);
	$goods_exists=1;
}
else{
    $titles='淘宝返现';
}

foreach($no_words as $v){
	if(strpos($titles,$v)!==false){
	    $titles=str_replace($v,'***',$titles);
	}
}

//******************简易模式，不获取返现和掌柜信息********************
if(WEBTYPE==1){
    //获取掌柜基本信息
    $Taoapi->method = 'taobao.user.get';
    $Taoapi->fields = 'user_id,nick,consumer_protection,seller_credit,location,type';
    $Taoapi->nick = $sellernick;
    $TaoapiUsers = $Taoapi->Send('get','xml')->getArrayData();
    $Result_users = $TaoapiUsers["user"];
    $uid=$Result_users["user_id"];
    $nick=$Result_users["nick"];
    $shoptype=$Result_users["type"];
    $shoplevel=$Result_users["seller_credit"]["level"];
    $consumer_protection=$Result_users["consumer_protection"];
    $shopstate=$Result_users["location"]["state"];
    $shopcity=$Result_users["location"]["city"];
    $total_num=$Result_users["seller_credit"]['total_num'];
    $good_num=$Result_users["seller_credit"]['good_num'];
    $shopscore=$Result_users["seller_credit"]["score"];
    $good=round($good_num/$total_num*100,2);
	
	if($sellernick!='' && $total_num>0){
        $Taoapi->method = 'taobao.shop.get';
        $Taoapi->fields = 'sid,cid,title,pic_path,created,shop_score';
        $Taoapi->nick = $sellernick;
        $ShopData = $Taoapi->Send('get','xml')->getArrayData();
        $Result_shop=$ShopData['shop'];
        $shoptitle=$Result_shop['title'];
        $item_score=$Result_shop["shop_score"]["item_score"];
        $service_score=$Result_shop["shop_score"]["service_score"];
        $delivery_score=$Result_shop["shop_score"]["delivery_score"];
        $shopcreated=$Result_shop['created'];
        $sid=$Result_shop['sid'];
        $shoppic=$Result_shop['pic_path'];
		
		$shop_pic_url="http://logo.taobao.com/shop-logo/".$shoppic;

        if($shoptype=='B'){
            $onerror="images/tbsc.gif";
	        if (is_array($shoppic)) {
		        $shop_pic_url = $onerror;
	        }
        }
        elseif($shoptype == "C"){
            $onerror="images/tbdp.gif";
	        if (is_array($shoppic)) {
		        $shop_pic_url = $onerror;
	        }
        }

        $Taoapi->method = 'taobao.taobaoke.shops.convert';
        $Taoapi->fields = 'commission_rate,click_url';
        $Taoapi->sids = $Result_shop['sid'];
        $Taoapi->nick = MYUSERNICK;
        $ShopComm = $Taoapi->Send('get','xml')->getArrayData();
        $fanxianlv=$ShopComm['taobaoke_shops']['taobaoke_shop']['commission_rate']?$ShopComm['taobaoke_shops']['taobaoke_shop']['commission_rate']:0;
        $shop_click_url=$ShopComm['taobaoke_shops']['taobaoke_shop']['click_url']?$ShopComm['taobaoke_shops']['taobaoke_shop']['click_url']:'http://shop'.$sid.'.taobao.com/';
    } 
    
	if($cid>0){
	    $TaobaokeParam['method'] = 'taobao.taobaoke.items.get';
        $TaobaokeParam['fields'] = 'iid,num_iid,title,nick,pic_url,price,click_url,shop_click_url,commission,commission_rate,commission_num,commission_volume,volume';
        $TaobaokeParam['nick'] = MYUSERNICK;
        $TaobaokeParam['cid']=$cid;
        $TaobaokeParam['start_credit']='1crown';
        $TaobaokeParam['end_credit']='5goldencrown';
        $TaobaokeParam['start_price']='20';
        $TaobaokeParam['end_price']='5000';
        $TaobaokeParam['sort']='commissionNum_desc';
        $TaobaokeParam['page_no']='1';
        $TaobaokeParam['page_size']='6';
        $TaobaokeParam['outer_code'] = $_SESSION['dduserid'];
        $Taoapi->setUserParam($TaobaokeParam);
        $TaobaokeData2 = $Taoapi->Send('get','xml')->getArrayData();
        $ListHot = $TaobaokeData2["taobaoke_items"]["taobaoke_item"];
	}
}
//******************简易模式，不获取返现和掌柜信息**********************

$page=$_GET['page'];
if($page==''){$page=1;}

$plurl="http://rate.taobao.com/detail_rate.htm?userNumId=".$uid."&auctionNumId=".$iid."&showContent=2&currentPage=".$page."&ismore=1&siteID=7";

$pagesize=20;
$totalpj=100;
$tag="list";
$pagetag='view';
include_once 'comm/wjt.php';
include_once 'comm/seo.php';
//引入模版文件
include 'template/'.MOBAN.'/view.tpl.php';

mysql_close($cfg_link);
?>